/**
 * OPBillTableSelectionListener.java
 * @author pkendzo
 * Email: pkendzo@msn.com
 * 2010
 */
package lu.med.praxiswahl.wahlumed.client.rechnungen.op.controller;

import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import lu.med.praxiswahl.wahlumed.client.rechnungen.op.model.OPBillTableModel;


/**
 * @author pkendzo
 *
 */
public class OPBillTableSelectionListener implements ListSelectionListener
{
    
    private OPBillTableModel model;
    
    public OPBillTableSelectionListener(OPBillTableModel model)
    {
	this.model = model;
    }

    /* (non-Javadoc)
     * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
     */
    @Override
    public void valueChanged(ListSelectionEvent e)
    {

	if (e.getValueIsAdjusting())
	{
	    return;
	}
	ListSelectionModel lsm = (ListSelectionModel) e.getSource();
	if (lsm.isSelectionEmpty())
	{
	    model.setSelected(-1);
	}
	else
	{
	    int selectedRow = lsm.getMinSelectionIndex();
	    model.setSelected(selectedRow);
	}
	

    }

}
